//==========================================================================
// Copyright (c) 2000-2008,  Elastos, Inc.  All Rights Reserved.
//==========================================================================
#include "ddk.h"

#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <time.h>

#include <misc.h>
#include <fat.h>
#include <fatfile.h>

Boolean StrToFName(PByte ncp, const wchar_t * *pcp)
{
    wchar_t c;
    const wchar_t * cp = *pcp;
    Boolean Ret = TRUE;

    while ((c = *cp) != EOS) {
        if ((Byte) c != '\n')
            *ncp++ = (Byte) c;
        cp++;
    }

    *ncp = '\0';
    Ret = FALSE;

    *pcp = cp;
    return Ret;
}

CFatFile::CFatFile()
{
    f_perm = 0;
    f_pos = 0;
    f_node = NULL;
    f_rename_id = 0;
    pFatDir = NULL;
    RefCnt = 0;
}

UInt32  CFatFile::
AddRef()
{
    return InterlockedIncrement((PInt32)&RefCnt);
}

UInt32  CFatFile::
Release()
{
    UInt32 Refs;

    Refs = InterlockedDecrement((PInt32)&RefCnt);
    if (Refs == 0) {
        pFatDir->fatfs_close(this);
        pFatDir->Release();
        delete this;
    }
    return Refs;
}
